package cn.gmy;

import java.io.IOException;
import java.util.Random;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import org.junit.Test;

public class Demo04_SequenceFile {	
	@Test
	public void testCreateSeq() throws IOException {
		SequenceFile.Writer.Option o1= SequenceFile.Writer.file(new Path("D:/a/1.seq"));
		SequenceFile.Writer.Option o2=SequenceFile.Writer.keyClass(LongWritable.class);
		SequenceFile.Writer.Option o3=SequenceFile.Writer.valueClass(Test.class);
		SequenceFile.Writer writer= SequenceFile.createWriter(new Configuration(), o1,o2,o3);
		
		Text text=new Text();
		LongWritable key=new LongWritable();
		
		Random random=new Random();
		for(int i=0;i<100;i++) {			
			key.set(random.nextInt(1000));
			text.set("Jack");
			writer.append(key, text);
		}
		writer.close();
	}
}
